8. TCP and UDP

TCP (Transmission Control Protocol)
It is used in the transmission of data over networks.
It is responsible for ensuring reliability during transmission. Means:

  1. All the packets reach the destination, that is no packet is lost.
  2. There is no such delay that would affect data quality.
  3. All data packets are reassembled in order.

TCP labels its packets (they are numbered). It also makes sure they have a deadline to reach the destination (time-out).
It performs 3 way handshake for reliability.
It uses IP and numbers (ports) provided by the device it is working on to identify where it is receiving and sending packets and for which service.
For example, web browsers uses port 80 for TCP, email uses port 25. The port number is often coupled with the IP address for a service, e.g. 192.168.66.5:80


Packet Structure:

9e38519c857541241f2551a95ed312cd.png

Row 1

Row 2

Row 3

3-way Handshake:

a8f94e0de8a69eec43f5b5fca0ff4258.png

In this way, TCP is reliable (in contrast, UDP does not do this and is therefore unreliable).

Row 4

ea93cb2552b3e5f07cd61f8e3f778d4e.png

d82ae9c08bb201d58488ea694618d399.png

a1bc5e10182d431a5a2c4f6f6852548d.png

PSH: Indicates to push the data past the buffer to the application as soon as possible.

Buffer!, What ?
A buffer is a chunk of memory that stores packets temporarily when there is too much data sent to a network interface (either generated by the host, or in the case of a switch or router, received from a different interface).
Packets get dropped if the buffer memory is full.

Understanding The PUSH (PSH)
Transport layer by default waits for some time for Application layer to send enough data so that the number of packets transmitted on network minimizes which is not desirable by some application like interactive applications (chatting).

Similarly at receiver end Transport layer buffers packets and transmit to Application layer if it meets certain criteria.

This problem is solved by using PSH. Transport layer sets flag PSH = 1 and immediately sends the segment to network layer as soon as it receives signal from application layer.
At receiver's end transport layer (on seeing PSH = 1) immediately forwards the data to application layer.
In general, it tells the receiver to process these packets as they are received instead of buffering them.

a1b1b438d4ca8b4313610add54f80290.png

dbbef27a0d38f21f476229c00fa41ded.png

Flow control?
TCP manages data buffers and coordinates traffic so its buffers will never overflow. Fast senders will be stopped periodically to keep up with slower receivers.

Row 5


UDP (User Datagram Protocol)
It is unreliable because it uses a simple connectionless communication model.
It is often used in video conferencing applications or computer games that are made specifically for real-time performance.
To achieve higher performance, the protocol allows individual packets to be dropped (with no retries) and UDP packets are received in a different order than they were sent.
In UDP, checksumming is optional, as opposed to TCP where checksums are mandatory.
Because UDP is limited in capability compared to TCP, its headers are smaller.

Packet Structure:

323e91d4e922607d8065a95802fa3eda.png